package Q1;

public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param str string字符串
     * @return int整型
     */
    public static int getLongestPalindrome (String str) {
        // write code here

        int len = str.length();

        if (len == 1) {
            return 1;
        }

        int ret = 0;
        for (int i = 0; i < len; i++) {
            char ch = str.charAt(i);
            for (int j = len - 1; j >= i; j--) {
                if (str.charAt(j) == ch) {
                    int left = i, right = j;
                    while (left < right) {
                        if (str.charAt(left) == str.charAt(right)) {
                            left++;
                            right--;
                        }
                    }
                    if (left == right || right + 1 == left) {
                        ret = Math.max(ret, j - i + 1);
                    }
                }
            }
        }

        return ret;
    }

    public static void main(String[] args) {
        System.out.println(getLongestPalindrome("bb"));
    }
}